package main

import (
	"flag"
	"fmt"
	"os"
)

type DataBaseUser struct {
	user, pwd, host string
	port            int
}

func main() {
	fmt.Println("命令行参数个数:", len(os.Args))
	for i, v := range os.Args {
		fmt.Println(i, v)
	}
	var user1 DataBaseUser
	flag.StringVar(&user1.user, "u", "", "用户名默认为空")
	flag.StringVar(&user1.pwd, "pwd", "", "密码默认为空")
	flag.StringVar(&user1.host, "host", "localhost", "主机名,默认localhost")
	flag.IntVar(&user1.port, "port", 3306, "端口默认3306")

	//必须解析上面的才能用
	flag.Parse()
	fmt.Println(user1)
}
